<?php

class Form_Place extends Zend_Form  {
	public function __construct($category_id = null)
	{
		parent::__construct();
        $this->setName("place");
        $name = new Zend_Form_Element_Text('name');
        $name->setRequired(true)
        	 ->addFilter("StripTags")
        	 ->addFilter("StringTrim")
        	 ->setLabel('Название места:');
       	$name->setAttribs(array('id'=>'edit_add1', 'class'=>'text'));

       	$category = new Model_Category_Place($category_id);
       	
       	$category1 = new Zend_Form_Element_Select('parent_category1');
       	$category1->clearDecorators()
       		->addDecorator("ViewHelper")
       		->setRequired(true)
       		->setAttrib('class', 'sel-f parent');
       	$parents  = $category->getLevel(0);
       	Zend_Debug::dump($parents->toArray());
       	foreach($parents as $parent){
       		$category1->addMultiOption($parent->id,$parent->name);
       	}
       	
       	$category1->clearValidators();
       	$category2 = new Zend_Form_Element_Select('child_category1'); 
       	$category2->clearDecorators()->addDecorator("ViewHelper")
        	 	  ->setAttrib('class', 'sel-f');
		$category2->clearValidators();
      
        if($category->getRow()){
        	  $childrens = $category->getChildren();
        } else {
        	$parent = new Model_Category_Place($parents[0]->id);
        	$childrens = $parent->getChildren();
        }
        foreach ($childrens as $chidlren){
        	
        	$category2->addMultiOption($chidlren->id,$chidlren->name);
        }	 	  
        
        $category1->setValue($category_id);
		
       	$adress = new Zend_Form_Element_Text('address');
       	$adress->setRequired(true)
       			->addFilter("StripTags")
        	 	->addFilter("StringTrim")
        	 	->setLabel('Адрес:')
        	 	->setAttrib('class', 'text');

        $mail = new Zend_Form_Element_Text('mail');
        $mail->addFilter("StripTags")
        	 ->addFilter("StringTrim")
        	 ->addValidator('EmailAddress')
        	 ->setLabel('e-mail:')
        	 ->setAttrib('class', 'text');
        	 
       	$work = new Zend_Form_Element_Text('work');
       	$work->setRequired(true)
       		 ->addFilter("StripTags")
        	 ->addFilter("StringTrim")
        	 ->setLabel('Режим работы:')
        	 ->setAttrib('class', 'text');
        	 
       	$phone = new Zend_Form_Element_Text('phone');
       	$phone->addFilter("StripTags")
        	  ->addFilter("StringTrim")
        	  ->setLabel('Телефоны:')
        	  ->setAttrib('class', 'text');
        	  
       	$site = new Zend_Form_Element_Text('site');
       	$site->addFilter("StripTags")
        	  ->addFilter("StringTrim")
        	  ->setLabel('Сайт:')
        	  ->setAttrib('class', 'text');
        	  	 
        $about = new Zend_Form_Element_Textarea('about');
        $about->addFilter("StripTags")
        	  ->addFilter("StringTrim")
        	  ->setLabel('Описание:')
        	  ->setAttribs(array('cols'=>10, 'cols'=>'10','class'=>'text-a text')); 
        
        $submit = new Zend_Form_Element_Submit('submit');
        $submit->setLabel('Добавить')->setAttrib('class','button-add');
        
        
        $this->addElements(array($name, $adress, $category1, $category2, $mail, $work, $phone, $site, $about, $submit));
        
        foreach($this->getElements() as $element){
        	$element->clearDecorators()->addDecorator("ViewHelper")
        	->addDecorator("Errors");
        }
	}
}